//
//  NevarByItems.m
//  lyxluyou
//
//  Created by mmyy on 15/10/17.
//  Copyright (c) 2015年 mmyy. All rights reserved.
//

#import "NevarByItems.h"
#import "CoreData+MagicalRecord.h"
@implementation NevarByItems
@dynamic cover_s;
@dynamic name;
@dynamic rating;
@dynamic rating_users;
@dynamic recommended_reason;
@dynamic wish_to_go_count;
@dynamic visited_count;
@dynamic vid;
@dynamic category;
@dynamic isSearch;
+(instancetype)nevarByItemsWithDict:(NSDictionary *)dict isSearch:(BOOL)search
{
    NevarByItems *items = [NevarByItems MR_createEntity];
    items.cover_s = dict[@"cover_s"];
    items.name = dict[@"name"];
    items.rating = dict[@"rating"];
    items.rating_users = dict[@"rating_users"];
    if (![[dict objectForKey:@"recommended_reason"] isKindOfClass:[NSNull class]]) {
        items.recommended_reason = dict[@"recommended_reason"];
    }
    items.wish_to_go_count = dict[@"wish_to_go_count"];
    items.visited_count = dict[@"visited_count"];
    items.vid = [dict[@"id"] stringValue];
    items.category = dict[@"category"];
//    items.isSearch = search;
    [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
    return items;

}

+(NSArray *)getDataWithCategory:(NSNumber *)category
{
    NSArray *array = [NevarByItems MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"category = %@", category]];
    return array;

}

+(void)removeAllDataWithCategory:(NSNumber *)category
{
    NSArray *array = [NevarByItems MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"category = %@", category]];
    for (NevarByItems *items in array) {
        [items MR_deleteEntity];
        [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
    }

}
+(void)removeDataWithIsSearch:(BOOL)isSearch
{
    NSArray *array = [NevarByItems MR_findAllWithPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"isSearch = %d", isSearch]]];
    for (NevarByItems *items in array) {
        [items MR_deleteEntity];
        [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
    }

}
@end
